import { defineStore } from 'pinia'
import axios from 'axios';
import mockAxios from '../plugins/mock_axios';
import _ from 'lodash';

const myaxios=mockAxios(axios);

export const useAttenderStore = defineStore({

  id: 'attender',
  state: () => ({
    attender: {}//{id,name,clazzId}
  }),
  getters: {
   // doubleCount: (state) => state.counter * 2
  },
  actions: {
/**
 * 根据考勤员id获取考勤员的完整信息
 * @param {*} id 考勤员信息
 */
    async fetchAttender(id){
      this.attender.id=id;
      myaxios.get(`/attender/${id}`,{ r:  { id: 1, name: 'lxf', clazzId: 1 }  }).then(r => {
        this.attender = r;
      })
    },

    async fetchStudentsByClazzId(){
      return myaxios.get(`/attender/studentsByClazzId/${this.attender.clazzId}`,{r:[
        {id:1,name:'lxf'},{id:2,name:'xxx'}
      ]})
    },

    /**
     * 根据clazzId获取可行的课表
     * TODO 应该过滤成当前学期的，为了测试和做题方便。
     * @returns 
     */
    async fetchAvaliableCurriculumsByClazzId(){
      return await myaxios.get(`/attender/avaliableCurriculumsByClazzId/${this.attender.clazzId}`,{r:[
       {id:1
        ,courseId:1,courseName:'数据库分析与设计'
        ,teacherId:1,teacherName:'刘笑锋'
        ,startFrom:230205203,hours:3}
      ,{id:2
        ,courseId:2,courseName:'数据库应用技术'
        ,teacherId:2,teacherName:'黄乐丹'
        ,startFrom:230205210,hours:3}
      ]})
    },

    /**
     * 
     * @param {*} studentStates 学生出勤状况[{id:1,state:'已签'}]
     * @param {*} cirriculumSelected 选中的课表条目{id:1}
     * @param {*} code 验证码
     * @returns 
     */
    async confirmAttend(studentStates,cirriculumSelected,code){
      return await myaxios.post(`/attender/newConfirmedAttendence`,{
        //TODO 给定参数
        r:1}) 
    },
/**
 * 
 * @param {*} clazz_id 根据班级id获得该班级所有考勤表(根据授课时间倒序排列)
 * @returns 
 */
    async fetchAttendencesOfClazzId(){
      return await myaxios.get(`/attender/attendencesOfClazzId/${this.attender.clazzId}`,{
        r:[{
           startFrom:230211203,
           hours:3,
           teacherId:1,
           teacherName:'刘笑锋',
           courseId:1,
           courseName:'数据库分析与设计',
           clazzId:1,
           clazzName:'软件2203',
           state:'未确认',
           attenderId:1,
           attenderName:'考勤员01'
        },{
            startFrom:230211206,
            hours:3,
            teacherId:1,
            teacherName:'刘笑锋',
            courseId:1,
            courseName:'数据库分析与设计',
            clazzId:1,
            clazzName:'软件2203',
            state:'未确认',
            attenderId:1,
            attenderName:'考勤员01'

        }]});
    },
/**
 * 获取本班同学们本学期的出勤成绩分数（但并没有进行排序）
 * @returns 本班所有同学们本学期的出勤成绩分数（但并没有进行排序）
 */
    async fetchScoresOfStudentsByClazzId(){
      return await myaxios.get(`/attender/scoresOfStudentsByClazzId/${this.attender.clazzId}`,{
        r:[{id:1,number:2302020034,name:'张三',score:10}
          ,{id:2,number:2302020044,name:'李四',score:12}
        ]});
    }
   

  }
})
